import { useState, useCallback } from 'react';

/**
 * Prompt Hook
 * 用于管理输入对话框
 */
export const usePrompt = () => {
  const [promptState, setPromptState] = useState(null);

  const showPrompt = useCallback(({
    title = '输入',
    message = '',
    defaultValue = '',
    placeholder = '',
    type = 'text'
  }) => {
    return new Promise((resolve) => {
      setPromptState({
        title,
        message,
        defaultValue,
        placeholder,
        type,
        onConfirm: (value) => {
          setPromptState(null);
          resolve(value);
        },
        onCancel: () => {
          setPromptState(null);
          resolve(null);
        }
      });
    });
  }, []);

  return {
    promptState,
    showPrompt
  };
};

